#include <REGX52.H>
#include "TIMER1.h"

sbit Moter=P1^0;

unsigned char Counter,Compare;//计数值和比较值，用于输出PWM

void Moter_Init(void)
{
	Timer1_Init();
}

void Moter_SetSpeed(unsigned char Speed)
{
	Compare=Speed;
}

//每隔100us进来一次
void Timer1_Routine() interrupt 1
{
	TL0 = 0x9C;				//设置定时初始值
	TH0 = 0xFF;				//设置定时初始值
	Counter++;
	Counter%=100;//Counter范围是1~100,100*100us=10ms,T=10ms
	if(Counter<Compare)Moter=1;
	else Moter=0;
}